package com.zhuiYun.project.api.order.controller;


import com.alipay.api.AlipayApiException;
import com.zhuiYun.project.api.alipay.entity.AlipayEntity;
import com.zhuiYun.project.api.order.entity.OrdersAfterSales;
import com.zhuiYun.project.api.order.entity.SubmitOrderVo;
import com.zhuiYun.project.api.order.service.OrderService;
import com.zhuiYun.project.common.errorCode.CommonException;
import com.zhuiYun.project.common.response.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @ClassName OrderController
 * @Description TODO 订单后台接口
 * @Author lzy
 * @Date 2023/4/3 10:07
 **/
@RestController
@RequestMapping("/order")
@Api(tags = "订单接口")
@Slf4j
@CrossOrigin
public class OrderController {

    @Autowired
    OrderService orderService;

    /**
    * @Description 询问当前订单状态
    * @Author lzy
    * @Date 2023/4/12 15:53
    * @Return com.zhuiYun.project.common.response.CommonResult
    * @param alipayEntity
    */
    @PostMapping("/getDiyOrderQuery")
    public CommonResult getDiyOrderQuery(@RequestBody AlipayEntity alipayEntity) throws CommonException, AlipayApiException {
        return orderService.getDiyOrderQuery(alipayEntity);
    }

    /**
    * @Description 用户提交订单
    * @Author lzy
    * @Date 2023/4/7 9:38
    * @Return com.zhuiYun.project.common.response.CommonResult
    * @param submitOrderVo
    */
    @PostMapping("/submitCommodityOrder")
    @ApiOperation("用户提交商品订单")
    public CommonResult submitCommodityOrder(@RequestBody SubmitOrderVo submitOrderVo) throws CommonException {
        return orderService.submitCommodityOrder(submitOrderVo);
    }

    /**
    * @Description 提交diy商品订单
    * @Author lzy
    * @Date 2023/4/19 11:25
    * @Return com.zhuiYun.project.common.response.CommonResult
    * @param submitOrderVo
    */
    @PostMapping("/submitHandDiyOrder")
    @ApiOperation("用户提交diy订单")
    public CommonResult submitHandDiyOrder(@RequestBody SubmitOrderVo submitOrderVo){
        return orderService.submitHandDiyOrder(submitOrderVo);
    }

    /**
    * @Description 取消diy订单
    * @Author lzy
    * @Date 2023/4/24 10:38
    * @Return com.zhuiYun.project.common.response.CommonResult
    * @param orderId
    */
    @PostMapping("/cancelDiyOrder")
    public CommonResult cancelDiyOrder(Integer orderId) throws CommonException{
        return orderService.cancelDiyOrder(orderId);
    }

    /**
     *
     * @author: HKY
     * @date: 2023/4/24 13:49
     * @param orderId
     * @return com.zhuiYun.project.common.response.CommonResult
     * @Description: 取消商品订单
     */
    @PostMapping("/cancelCommodityOrder")
    public CommonResult cancelCommodityOrder(Integer orderId) throws CommonException{
        return orderService.cancelCommodityOrder(orderId);
    }

    /**
        * @Author yuanb
        * @Description 获取订单商品详细信息列表方法 (用于pc端订单详细详细查询)
        * @Date 2023/4/9 15:56
        * @Return com.zhuiYun.project.common.response.CommonResult
        * * @param userId
    */
    @GetMapping("/getInformation")
    @ApiOperation(value = "获取订单商品详细信息列表方法")
    public CommonResult getInformation(Integer userId,Integer id) throws CommonException{
        return CommonResult.ok(orderService.getInformation(userId,id));
    }
    /**
     * @Author yuanb
     * @Description 获取订单diy详细信息列表方法 (用于pc端订单详细详细查询)
     * @Date 2023/4/9 15:56
     * @Return com.zhuiYun.project.common.response.CommonResult
     * * @param userId
     */
    @GetMapping("/getDiyInformation")
    @ApiOperation(value = "获取订单diy详细信息列表方法")
    public CommonResult getDiyInformation(Integer userId,Integer id) throws CommonException{
        return CommonResult.ok(orderService.getDiyInformation(userId,id));
    }

    /**
        * @Author yuanb
        * @Description pc端我的订单获取用户所有订单的方法
        * @Date 2023/4/17 19:53
        * @Return com.zhuiYun.project.common.response.CommonResult
        * * @param userId
    */
    @GetMapping("/getMyAllOrderPc")
    @ApiOperation(value = "pc端我的订单获取用户所有订单的方法")
    public CommonResult getMyAllOrderPc(Integer userId) throws CommonException{
        return CommonResult.ok(orderService.getMyAllOrderPc(userId));
    }
    /**
     * @Author yb
     * @Description 查询点击状态的订单信息（用于我的订单中订单状态栏）
     * @Date 2023-04-07 上午 09:41
     * @Return CommonResult
     * @param userId
     * @param status
     */
    @GetMapping("/getStatusToOrderPc")
    public CommonResult getStatusToOrderPc(Integer status,Integer userId){
        return orderService.getStatusToOrderPc(status,userId);
    }
    /**
     * @Author gpd
     * @Description 查询用户所有的订单信息
     * @Date 2023-04-04 上午 09:17
     * @Return  CommonResult
     * @param userId
     */
    @GetMapping("/getMyAllOrder")
    @ApiOperation(value = "uniapp我的订单获取用户所有订单的方法")
    public CommonResult getMyAllOrder(Integer userId) throws CommonException{
        return CommonResult.ok(orderService.getMyAllOrder(userId));
    }

    /**
    * @Author gpd
    * @Description 搜索查询用户订单信息（用于uniapp我的订单搜索栏）
    * @Date 2023-04-06 下午 08:56
    * @Return CommonResult
     * @param userId
     * @param myOrderValue
     */
    @GetMapping("/getSelectOrderList")
    public CommonResult getSelectOrderList(String myOrderValue,Integer userId){
        return orderService.getSelectOrderList(myOrderValue,userId);
    }

    /**
    * @Author gpd
    * @Description 查询点击状态的订单信息（用于我的订单中订单状态栏）
    * @Date 2023-04-07 上午 09:41
    * @Return CommonResult
     * @param userId
     * @param status
    */
    @GetMapping("/getStatusToOrder")
    public CommonResult getStatusToOrder(Integer status,Integer userId){
        return orderService.getStatusToOrder(status,userId);
    }
    /**
        * @Author yuanb
        * @Description 详情步骤条查询方法
        * @Date 2023/4/10 15:44
        * @Return com.zhuiYun.project.common.response.CommonResult
        * * @param userId
        * @param id
    */
    @GetMapping("/getStepList")
    public CommonResult getStepList(Integer userId, Integer id){
        return orderService.getStepList(userId,id);
    }

    /**
        * @Author yuanb
        * @Description 获取售后列表(pc端)
        * @Date 2023/4/11 16:38
        * @Return com.zhuiYun.project.common.response.CommonResult
        * * @param userId
    */
    @GetMapping("/getAfterSalesList")
    @ApiOperation(value = "获取售后列表")
    public CommonResult getAfterSalesList(Integer userId){
        return orderService.getAfterSalesList(userId);
    }


    /**
        * @Author yuanb
        * @Description 添加售后列表(pc端)
        * @Date 2023/4/11 16:38
        * @Return com.zhuiYun.project.common.response.CommonResult
        * @param OrdersAfterSales
    */
    @PostMapping("/AfterSalesList")
    @ApiOperation(value = "添加售后列表")
    public CommonResult AfterSalesList(OrdersAfterSales OrdersAfterSales, MultipartFile file) throws CommonException {
        return orderService.AfterSalesList(OrdersAfterSales,file);
    }

    /**
        * @Author yuanb
        * @Description
        * @Date 2023/4/15 9:30
        * @Return com.zhuiYun.project.common.response.CommonResult
        * @param id
    */
    @DeleteMapping("/updateOrder")
    @ApiOperation(value = "修改订单状态")
    public CommonResult updateOrder(Integer id) throws CommonException {
        return orderService.updateOrder(id);
    }

    /**
        * @Author yuanb
        * @Description 查询订单支付状态
        * @Date 2023/4/16 19:12
        * @Return com.zhuiYun.project.common.response.CommonResult
        * * @param id
    */
    @GetMapping("/getId")
    @ApiOperation(value = "查询订单支付状态")
    public CommonResult getId( Integer id){
        return orderService.getId(id);
    }

 }
